﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using KF.Common;
using KF.DHL.DAL;


namespace KF.DHL.DAL
{
    public class PriceInfo
    {
        public List<KF.DHLModel.PriceInfo> GetPriceInfo()
        {
            DataSet ds = new DataSet();
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select * from ZonePrice ");


            try
            {
                Database db = DatabaseFactory.CreateDatabase(DBConfig.Pricing);
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());


                ds = db.ExecuteDataSet(dbCommand);

                List<KF.DHLModel.PriceInfo> infos = new List<DHLModel.PriceInfo>();


                KF.DHLModel.PriceInfo info;

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    info = new DHLModel.PriceInfo();
                    info.ID = Convert.ToInt32(dr["ID"]);
                    info.StartWeight = Convert.ToDouble(dr["StartWeight"]);
                    info.EndWeight = Convert.ToDouble(dr["EndWeight"]);
                    info.Price = Convert.ToDouble(dr["Price"]);
                    info.Zone = Convert.ToInt32(dr["Zone"]);
                    info.Type = (KF.DHLModel.CustomerType)Convert.ToInt32(dr["Type"]);
                    info.PriceType = (KF.DHLModel.PriceType)Convert.ToInt32(dr["PriceType"]);
                    info.ItemType = (KF.DHLModel.ItemType)Convert.ToInt32(dr["ItemType"]);
                    infos.Add(info);
                }

                return infos;


            }
            catch (System.Exception ex)
            {
                LogHelper.DebugHelper.WriteLog(ex.ToString(), LogHelper.ExceptionHelper.ExceptionLevel.Exception);
                return null;
            }
        }
    }
}
